package cn.mldn.micorcloud.config;

import java.nio.charset.Charset;
import java.util.Base64;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestConfig {

	// 要进行一个Http头信息配置
	@Bean
	public HttpHeaders getHeaders() {
		// 定义一个头信息的配置
		HttpHeaders headers = new HttpHeaders();
		// 认证的原始信息
		String auth = "mldnjava:hello";

		// 进行加密处理
		byte[] encodeAuth = Base64.getEncoder().encode(auth.getBytes(Charset.forName("US-ASCII")));

		// 头信息的处理{"Basic"里面必须加上空格}
		String authHeader = "Basic " + new String(encodeAuth);
		headers.set("Authorization", authHeader);
		return headers;
	}

	@Bean
	public RestTemplate getRestTemplate() {
		return new RestTemplate();
	}

}
